home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / datatypes / wavdt / source / classbase.c next >
C/C++ Source or Header  |  1996-04-07  |  4KB  |  163 lines

  1. /******************************************************************************
  2.  *
  3.  * WAV Datatype, based on the sourcecode found in OS3.1 Native Developer Kit
  4.  *
  5.  * Written by David N.Junod and Christian Buchner
  6.  *
  7.  ******************************************************************************
  8.  * classbase.c
  9.  *
  10.  */
  11.  
  12. #include "classbase.h"
  13.  
  14. /****** wav.datatype/wav.datatype ****************************************
  15. *
  16. *    NAME
  17. *    wav.datatype -- data type for wav sounds.
  18. *
  19. *    FUNCTION
  20. *    The wav data type, a sub-class of the sound.datatype, is used
  21. *    to load Windows WAV files.
  22. *
  23. *    METHODS
  24. *    OM_NEW -- Create a new sound object from a WAV file.  The
  25. *        source may be either a file or the clipboard.
  26. *
  27. *    SEE ALSO
  28. *    sound.datatype.
  29. *
  30. *******************************************************************************
  31. *
  32. * Created:  27-Feb-92, David N. Junod
  33. * Modified: 09-Jan-95, Christian Buchner
  34. *
  35. */
  36.  
  37. /*****************************************************************************/
  38.  
  39. Class *ASM ObtainWAVEngine (REG (a6) struct ClassBase *cb)
  40. {
  41.     return (cb->cb_Class);
  42. }
  43.  
  44. /*****************************************************************************/
  45.  
  46. struct Library *ASM LibInit (REG (d0) struct ClassBase *cb, REG (a0) BPTR seglist, REG (a6) struct Library * sysbase)
  47. {
  48.     cb->cb_SegList = seglist;
  49.     SysBase = (struct ExecBase*)sysbase;
  50.     InitSemaphore (&cb->cb_Lock);
  51.     if (((struct Library *)SysBase)->lib_Version >= 39)
  52.     {
  53.         DOSBase       = OpenLibrary ("dos.library",      39);
  54.         UtilityBase   = OpenLibrary ("utility.library",  39);
  55.         IntuitionBase = OpenLibrary ("intuition.library",39);
  56.         return cb;
  57.     }
  58.     else
  59.     {
  60.         return NULL;
  61.     }
  62. }
  63.  
  64. /*****************************************************************************/
  65.  
  66. LONG ASM LibOpen (REG (a6) struct ClassBase *cb)
  67. {
  68.     LONG retval = (LONG) cb;
  69.     BOOL success = TRUE;
  70.     
  71.     ObtainSemaphore (&cb->cb_Lock);
  72.     
  73.     /* Use an internal use counter */
  74.     cb->cb_Lib.lib_OpenCnt++;
  75.     cb->cb_Lib.lib_Flags &= ~LIBF_DELEXP;
  76.     
  77.     if (cb->cb_Lib.lib_OpenCnt == 1)
  78.     {
  79.         if (cb->cb_Class == NULL)
  80.         {
  81.             success = FALSE;
  82.             if (DataTypesBase = OpenLibrary ("datatypes.library", 0))
  83.                 if (cb->cb_SuperClassBase = OpenLibrary ("datatypes/sound.datatype", 39))
  84.                     if (cb->cb_Class = initClass (cb))
  85.                         success = TRUE;
  86.         }
  87.     }
  88.     
  89.     if (!success)
  90.     {
  91.         CloseLibrary (cb->cb_SuperClassBase);
  92.         CloseLibrary (DataTypesBase);
  93.         cb->cb_Lib.lib_OpenCnt--;
  94.         retval = NULL;
  95.     }
  96.     
  97.     ReleaseSemaphore (&cb->cb_Lock);
  98.     
  99.     return (retval);
  100. }
  101.  
  102. /*****************************************************************************/
  103.  
  104. LONG ASM LibClose (REG (a6) struct ClassBase *cb)
  105. {
  106.     LONG retval = NULL;
  107.     
  108.     ObtainSemaphore (&cb->cb_Lock);
  109.     
  110.     if (cb->cb_Lib.lib_OpenCnt)
  111.     cb->cb_Lib.lib_OpenCnt--;
  112.     
  113.     if ((cb->cb_Lib.lib_OpenCnt == 0) && cb->cb_Class)
  114.     {
  115.         if (FreeClass (cb->cb_Class))
  116.         {
  117.             CloseLibrary (cb->cb_SuperClassBase);
  118.             CloseLibrary (DataTypesBase);
  119.             cb->cb_Class = NULL;
  120.         }
  121.         else
  122.         {
  123.             cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
  124.         }
  125.     }
  126.     
  127.     if (cb->cb_Lib.lib_Flags & LIBF_DELEXP)
  128.     retval = LibExpunge (cb);
  129.     
  130.     ReleaseSemaphore (&cb->cb_Lock);
  131.     
  132.     return (retval);
  133. }
  134.  
  135. /*****************************************************************************/
  136.  
  137. LONG ASM LibExpunge (REG (a6) struct ClassBase *cb)
  138. {
  139.     BPTR seg = cb->cb_SegList;
  140.     
  141.     if (cb->cb_Lib.lib_OpenCnt)
  142.     {
  143.     cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
  144.     return (NULL);
  145.     }
  146.     
  147.     Remove ((struct Node *) cb);
  148.     
  149.     CloseLibrary (IntuitionBase);
  150.     CloseLibrary (UtilityBase);
  151.     CloseLibrary (DOSBase);
  152.     
  153.     FreeMem ((APTR)((ULONG)(cb) - (ULONG)(cb->cb_Lib.lib_NegSize)), cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  154.     
  155.     return ((LONG) seg);
  156. }
  157.  
  158. /*****************************************************************************/
  159.  
  160. void ASM LibReserved(REG (a6) struct ClassBase *cb)
  161. {
  162. }
  163.